import os
from  vtdb import adbcli
from common import hztool
from langchain_community.document_loaders import Docx2txtLoader,TextLoader
from langchain_community.document_loaders import PyPDFLoader
from langchain_community.document_loaders import DirectoryLoader
from langchain_community.embeddings import DashScopeEmbeddings
from langchain_text_splitters import RecursiveCharacterTextSplitter
from langchain.llms import Tongyi
from langchain.prompts import PromptTemplate
from langchain.prompts import PromptTemplate, ChatPromptTemplate
from langchain.chains import LLMChain

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import text
from sqlalchemy import create_engine
from db.mysqlconn import getMySession,myeng,mydbkey
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_core.runnables.history import RunnableWithMessageHistory
from langchain_community.chat_message_histories import SQLChatMessageHistory
from langchain_community.chat_message_histories import PostgresChatMessageHistory

from sqlalchemy.ext.automap import automap_base

from dao import mydao as md     
from dao import mydao

def getchatpp(id):
    pp= mydao.getPrompt(id)
    ppc=""
    if pp is not None:
        ppc=pp.content
    
    prompt_template = ChatPromptTemplate.from_messages([
        ("system", ppc ),
        ("user", "{question}")
        ])
    return prompt_template 

def gethispp(id):
    pp= mydao.getPrompt(id)
    ppc=""
    if pp is not None:
        ppc=pp.content

    prompt = ChatPromptTemplate.from_messages(
            [
                ("system",  ppc),
                MessagesPlaceholder(variable_name="history"),
                ("human", "{question}"),
            ]
        )
    
    return prompt 